/*
 * CAD System for seamlessly constructing 2D and 3D scenes with aspects and motion
 * Copyright (C) 2013 Bernhard Haumacher and others
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.haumacher.draw5d.math.d2.constructions;

import junit.framework.TestCase;
import de.haumacher.draw5d.math.d2.D2Base;

public abstract class D2TestCase extends TestCase {

	private static final double EPSILON = 0.0000001;

	public static void assertD2(double x, double y, D2Base result) {
		String message = "Expected " + point(x, y) + ", found " + point(result) + ".";
		assertEqualsLength(message, x, result.getX());
		assertEqualsLength(message, y, result.getY());
	}

	private static String point(D2Base p) {
		return point(p.getX(), p.getY());
	}

	private static String point(double x, double y) {
		return "(" + x + ", " + y + ")";
	}

	public static void assertEqualsLength(String message, double x1, double x2) {
		assertTrue(message, equalsLength(x1, x2));
	}

	public static boolean equalsLength(double x1, double x2) {
		return Math.abs(x1 - x2) < EPSILON;
	}

}
